package org.geeks.gsredisson.func;

import lombok.extern.slf4j.Slf4j;
import org.geeks.gsredisson.GsRedissonApplicationTests;
import org.junit.Test;
import org.redisson.api.RBucket;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.concurrent.TimeUnit;

@Slf4j
public class RBucketT extends GsRedissonApplicationTests {

  @Autowired private RedissonClient redissonClient;

  @Test
  public void set() {
    RBucket<String> rBucket = redissonClient.getBucket("k");

    rBucket.set("v0");

    log.info("Value is {}", rBucket.get());

    rBucket.trySet("v1");

    log.info("Value is {}", rBucket.get());

    rBucket.set("v1");

    log.info("Value is {}", rBucket.get());
  }

  @Test
  public void trySet() {
    RBucket<String> rBucket = redissonClient.getBucket("Temp");

    boolean flag = rBucket.trySet("xx", 8, TimeUnit.SECONDS);

    log.info("Flag is {}", flag);

    flag = rBucket.trySet("xx");

    log.info("Flag is {}", flag);
  }
}
